<?php

class Default_Model_Bookmark
{

    public $Name; 
    public $Group; 
    public $Items; 
    public $Count;
    public $Path; 
    public $Id; 
     
    function __construct($bookmarkPath=NULL)
    { 
        if (!$bookmarkPath) return; 
        $this->Populate ($bookmarkPath); 
    }  

    function Populate ($bookmarkPath, $sort=NULL) { 
        $articleList = simplexml_load_file($bookmarkPath);
        $this->Items = array();
        $result = $articleList->xpath("//articles/article");  
        for($x=0;$x<sizeof($result);$x++)
        { 
            $this->Items[] = new Default_Model_Article($result[$x]);
        } 
        $this->Count = sizeof($this->Items); 
        $group       = $articleList->xpath("//articles"); 
	    $this->Group = $group[0]->group; 
        $this->Name  = $this->Items[0]->subject;
        $this->Id    = $this->Items[0]->id;
        usort($this->Items, 'cmp2');
    }  

    function Load ($element) {
        $this->Name  = "{$element->Name}";
        $this->Group = "{$element->Group}";
        $this->Id    = "{$element->Id}";
        $this->Count = "{$element->Count}";
        $this->Path  = "{$element->Path}";
    }  


    function Serialize () {
        
        return "<bookmark>"
              . " <Name><![CDATA[{$this->Name}]]></Name>"
              . " <Group>{$this->Group}</Group>"
              . " <Count>{$this->Count}</Count>"
              . " <Path>{$this->Path}</Path>"
              . " <Id>{$this->Id}</Id>"
              . "</bookmark>";
    }
}


function cmp2($a, $b) { 
    return ($a->subject < $b->subject) ? -1 : 1;
}



